package com.supermarket.web.controller.supermarket;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.supermarket.business.domain.SupermarketSalesDetail;
import com.supermarket.business.dto.SupermarketSalesDetailDTO;
import com.supermarket.business.vo.SupermarketSalesDetailVO;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.supermarket.common.annotation.Log;
import com.supermarket.common.core.controller.BaseController;
import com.supermarket.common.core.domain.AjaxResult;
import com.supermarket.common.enums.BusinessType;
import com.supermarket.business.service.ISupermarketSalesDetailService;
import com.supermarket.common.utils.poi.ExcelUtil;
import com.supermarket.common.core.page.TableDataInfo;

/**
 * 销售明细Controller
 * 
 * @author ruoyi
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/supermarket/detail")
public class SupermarketSalesDetailController extends BaseController
{
    @Resource
    private ISupermarketSalesDetailService sysSalesDetailService;

    /**
     * 查询销售明细列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketSalesDetailDTO supermarketSalesDetailDTO)
    {
        startPage();
        SupermarketSalesDetail supermarketSalesDetail = new SupermarketSalesDetail();
        BeanUtils.copyProperties(supermarketSalesDetailDTO, supermarketSalesDetail);
        List<SupermarketSalesDetail> list = sysSalesDetailService.selectSysSalesDetailList(supermarketSalesDetail);
        return getDataTable(list);
    }

    /**
     * 导出销售明细列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:detail:export')")
    @Log(title = "销售明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupermarketSalesDetail supermarketSalesDetail)
    {
        List<SupermarketSalesDetail> list = sysSalesDetailService.selectSysSalesDetailList(supermarketSalesDetail);
        ExcelUtil<SupermarketSalesDetail> util = new ExcelUtil<SupermarketSalesDetail>(SupermarketSalesDetail.class);
        util.exportExcel(response, list, "销售明细数据");
    }

    /**
     * 获取销售明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:detail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(sysSalesDetailService.selectSysSalesDetailVOByDetailId(detailId));
    }

    /**
     * 新增销售明细
     */
    @PreAuthorize("@ss.hasPermi('supermarket:detail:add')")
    @Log(title = "销售明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupermarketSalesDetailDTO supermarketSalesDetailDTO)
    {
        SupermarketSalesDetail supermarketSalesDetail = new SupermarketSalesDetail();
        BeanUtils.copyProperties(supermarketSalesDetailDTO, supermarketSalesDetail);
        return toAjax(sysSalesDetailService.insertSysSalesDetail(supermarketSalesDetail));
    }

    /**
     * 修改销售明细
     */
    @PreAuthorize("@ss.hasPermi('supermarket:detail:edit')")
    @Log(title = "销售明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupermarketSalesDetailDTO supermarketSalesDetailDTO)
    {
        SupermarketSalesDetail supermarketSalesDetail = new SupermarketSalesDetail();
        BeanUtils.copyProperties(supermarketSalesDetailDTO, supermarketSalesDetail);
        return toAjax(sysSalesDetailService.updateSysSalesDetail(supermarketSalesDetail));
    }

    /**
     * 删除销售明细
     */
    @PreAuthorize("@ss.hasPermi('supermarket:detail:remove')")
    @Log(title = "销售明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(sysSalesDetailService.deleteSysSalesDetailByDetailIds(detailIds));
    }
}
